package com.study.easyexcel.business.entity;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.excel.annotation.format.NumberFormat;
import com.alibaba.excel.annotation.write.style.*;
import com.alibaba.excel.enums.poi.BorderStyleEnum;
import com.alibaba.excel.enums.poi.FillPatternTypeEnum;
import com.alibaba.excel.enums.poi.VerticalAlignmentEnum;
import com.study.easyexcel.api.annotation.DropdownBox;
import com.study.easyexcel.api.annotation.ExcelBind;
import com.study.easyexcel.api.converter.SexConverter;
import com.study.easyexcel.business.comment.AssetsComment;
import com.study.easyexcel.common.constant.RegexesConstants;
import com.study.easyexcel.common.domain.AdditionalImage;
import com.study.easyexcel.common.enums.ExcelPattern;

import java.math.BigDecimal;
import java.util.Date;

/**
 * Excel 数据导入导出的映射实体。如果实体没有指定列名或者列索引，导入数据时则以字段的顺序接收
 * PS: Get/Set方法最好纯手写，否则可能导致导入的数据为空
 * {@link ExcelProperty#value()}        指定列名，导出时会作为行头；多个值则代表多行头，其他单行头则自动合并单元格
 * {@link ExcelProperty#order()}        指定列；导出时，如果排除了指定列，会忽略空列，然后继续往后，优先级高于列名
 * {@link ExcelProperty#index()}        指定列；导出时，如果排除了指定列，不会忽略空列，在第几列就是第几列，优先级最高
 * {@link ExcelProperty#converter()}    指定当前字段用什么转换器，默认会自动选择。自定义{@link SexConverter}
 * {@link ExcelIgnoreUnannotated}       未添加{@link ExcelProperty}的字段不会参与读写
 * {@link ExcelIgnore}                  忽略这个字段，默认所有字段都会和excel去匹配
 * {@link NumberFormat}                 数字格式转换，百分比的数字{@code #.##%}
 * {@link DateTimeFormat}               日期格式转换
 * {@link ColumnWidth}                  指定列宽
 * {@link ContentRowHeight}             指定行高，作用于所有字段
 * {@link HeadRowHeight}                头的行高
 * {@link HeadFontStyle}                头字体设置
 * {@link HeadStyle}                    表头样式，背景色，对齐等
 * {@link ContentFontStyle}             内容字体设置
 * {@link ContentStyle}                 内容样式；声明边框可以防止数据在填充时缺失边框
 *
 * @author yuhuan
 * @date 2022/8/30
 */
@HeadRowHeight(26)
@HeadStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND,
        fillForegroundColor = 40, verticalAlignment = VerticalAlignmentEnum.CENTER)
@ContentStyle(borderBottom = BorderStyleEnum.THIN, borderTop = BorderStyleEnum.THIN,
        borderLeft = BorderStyleEnum.THIN, borderRight = BorderStyleEnum.HAIR)
@ExcelIgnoreUnannotated
public class Traveler extends AdditionalImage {

    @ExcelProperty(value = {"基础信息", "姓名"}, order = 1)
    @ColumnWidth(12)
    @ExcelBind(value = {ExcelPattern.SIZE}, name = "姓名", maxLen = 10)
    @DropdownBox(firstRow = 2, firstCol = 1, lastCol = 1)
    private String name;

    @ExcelProperty(value = {"基础信息", "性别"}, order = 2, converter = SexConverter.class)
    @DropdownBox(firstRow = 2, firstCol = 2, lastCol = 2, explicitList = {"男性", "女性", "未知"}, showErrorBox = true)
    private int sex;

    @ExcelProperty(value = {"基础信息", "生日"}, order = 3)
    @DateTimeFormat("yyyy-MM-dd HH/mm/ss")
    @ColumnWidth(20)
    private Date birthday;

    @ExcelProperty(value = {"基础信息", "资产"}, order = 4, converter = AssetsComment.class)
    @ColumnWidth(10)
    private BigDecimal assets;

    @ExcelProperty(value = {"基础信息", "手机号"}, order = 5)
    @ColumnWidth(13)
    @ExcelBind(value = ExcelPattern.PATTERN, regexes = RegexesConstants.PHONE_REGEX,
            message = "不是有效的手机号码")
    private String phone;

    @ExcelProperty(value = {"基础信息", "邮箱"}, order = 6)
    @ColumnWidth(13)
    @ExcelBind(value = ExcelPattern.PATTERN, regexes = RegexesConstants.EMAIL_REGEX,
            message = "不是有效的邮箱地址")
    private String email;

    @ExcelProperty(value = "编号", index = 0)
    @ExcelBind(value = {ExcelPattern.PATTERN, ExcelPattern.NOTNULL}, regexes = RegexesConstants.LETTER_NUMBER_REGEX,
            message = {"编号不能包含除大小写字母或者数字外的其他字符[{val}]", "编号不能为空"})
    private String code;

    @ExcelProperty(value = "家庭成员", order = 8)
    @ColumnWidth(20)
    @ExcelBind(value = ExcelPattern.SIZE, name = "成员名字", maxLen = 10, cut = true)
    private String family;

    @ExcelProperty(value = "信用度", order = 9)
    @NumberFormat("#.##%")
    private double process;

    private String remarks;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public BigDecimal getAssets() {
        return assets;
    }

    public void setAssets(BigDecimal assets) {
        this.assets = assets;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getFamily() {
        return family;
    }

    public void setFamily(String family) {
        this.family = family;
    }

    public Double getProcess() {
        return process;
    }

    public void setProcess(Double process) {
        this.process = process;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public void setProcess(double process) {
        this.process = process;
    }

    @Override
    public String toString() {
        return "Traveler{" +
                "name='" + name + '\'' +
                ", sex=" + sex +
                ", birthday=" + birthday +
                ", assets=" + assets +
                ", phone='" + phone + '\'' +
                ", email='" + email + '\'' +
                ", code='" + code + '\'' +
                ", family='" + family + '\'' +
                ", process=" + process +
                ", remarks='" + remarks + '\'' +
                '}';
    }
}
